
/**
 * 
 */
(function(window, undefined) {
	var RegExpSyntax = (function() {
		var formReg = /(<(\/?)(button|textarea|form|input|select|option|label|div|p|em).*?>)/g;
		var RegExpSyntax = function(options) {
			var settings = {
				dom : "",
				text : null
			};
			$.extend(settings, options);
			this.text = settings.text;
			buildNode = function(execResult, RegExp) {
				var node = {};
				node.index = execResult.index;
				node.tag = RegExp.lastParen;
				node.isStartTag = (RegExp.$2 == "");
				node.content = RegExp.lastMatch;
				return node;
			};
			buildElement = function(startTag, endTag, context) {
				var e = {};
				e.startIndex = startTag.index;
				e.endIndex = endTag.index;
				e.content = context.substring(this.startIndex, this.endIndex)
						+ "" + endTag.content;
				return e;
			};
			return this;
		};

		RegExpSyntax.prototype.parseHtml = function() {
			if (arguments[0]) {
				this.text = arguments[0];
			}
			if (this.text.replace(/\s/, "") === "") {
				return;
			}
			var tagArray = [];
			var eleArray = [];
			while (true) {
				temp = formReg.exec(this.text);
				if (temp == null)
					break;
				var tagObj = buildNode(temp, RegExp);
				if (!tagObj.isStartTag) {
					for (var index = tagArray.length - 1;index >= 0; index--) {
						var innerlastTag = tagArray[index];
						if (innerlastTag.isStartTag
								&& innerlastTag.tag == tagObj.tag) {
							var e = buildElement(innerlastTag, tagObj,
									this.text);
							eleArray.push(e);
							tagArray.splice(index, 1);
							break;
						}
					}
				} else {
					tagArray.push(tagObj);
				}
			}
			return eleArray;
		};

		return RegExpSyntax;
	})();
	window.RegExpSyntax = RegExpSyntax;
})(window);
var o = new RegExpSyntax( {
	text : "<div class=\"demo-container\">  <p>All new content. <em>You bet!</em></p></div>"
});
$.log(o);
$.log(o.parseHtml());